package org.zhb.querysql.core.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class FileSystem {

	public static final File TEMP_DIR = new File("temp");

	public static InputStream read(String path) throws FileNotFoundException {
		InputStream in = FileSystem.class.getClassLoader().getResourceAsStream(path);
		if (in == null) {
			throw new FileNotFoundException(path);
		}
		return in;
	}

	public static File createTempFile() throws IOException {
		return File.createTempFile("kikbug", ".tmp", TEMP_DIR);
	}

	public static File createTempFile(String ext) throws IOException {
		return File.createTempFile("kikbug", "." + ext, TEMP_DIR);
	}

	public static File createTempFile(File dir, String ext) throws IOException {
		return File.createTempFile("kikbug", "." + ext, dir);
	}

}
